#ifndef AUTH_H_INCLUDED
#define AUTH_H_INCLUDED
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <bson.h>
#define RE_AUTH " password"
#define RE_USER " user="
#define RE_UID " uid="
#define RE_IP4 "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"
#define RE_IP6 "/^\\s*((([0-9A-Fa-f]{1,4}:){7}(([0-9A-Fa-f]{1,4})|:))|(([0-9A-Fa-f]{1,4}:){6}(:|((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})|(:[0-9A-Fa-f]{1,4})))|(([0-9A-Fa-f]{1,4}:){5}((:((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){4}(:[0-9A-Fa-f]{1,4}){0,1}((:((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){3}(:[0-9A-Fa-f]{1,4}){0,2}((:((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){2}(:[0-9A-Fa-f]{1,4}){0,3}((:((25[0-5]|2[0-4]\\d| \
[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})?)| \
((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:)(:[0-9A-Fa-f]{1,4}){0,4} \
((:((25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})?)| \
((:[0-9A-Fa-f]{1,4}){1,2})))|(:(:[0-9A-Fa-f]{1,4}){0,5}((:((25[0-5]|2[0-4]\\d| \
[01]?\\d{1,2})(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})?)| \
((:[0-9A-Fa-f]{1,4}){1,2})))|(((25[0-5]|2[0-4]\\d|[01]?\\d{1,2}) \
(\\.(25[0-5]|2[0-4]\\d|[01]?\\d{1,2})){3})))(%.+)?\\s*$/"

#define RE_TIMESTAMP "[a-z]{3}[ ]{1,2}[0-9]{1,2}[ ]{1,2}[0-9]{2,2}[:,;][0-9]{2,2}[:,;][0-9]{2,2}"
#define RE_PROCESS "\\[[0-9]{1,6}\\]"
#define RE_PORT " port"
#define RE_STATUS "fail|success"
#define RE_MISC " for"


#define UNAME_MAX 255
#define STATUS_MAX 8
#define IP_MAX 100
#define TIMESTAMP_MAX 20
typedef struct
{
        regex_t status;
        regex_t user;
        regex_t uid;
        regex_t ip;
        regex_t timestamp;
        regex_t port;
        regex_t subject;
} CAUTHLOG;
typedef struct
{
		char status[STATUS_MAX];
        char user[UNAME_MAX];
        char ip[IP_MAX];
        char timestamp[TIMESTAMP_MAX];
        char destination[UNAME_MAX];
        char process[UNAME_MAX];
        char subject[UNAME_MAX];
        unsigned int uid;
        unsigned int port;
} AUTHLOG;

#ifdef __cplusplus
extern "C" {
#endif

int next_word(char *message,int num);
int next_num(char *message);
int compile(CAUTHLOG *ca);
int mmatch(AUTHLOG *temp,CAUTHLOG *ca,char *str);
int normalise(bson *,char *);
#ifdef __cplusplus
}
#endif


#endif // AUTH_H_INCLUDED
